home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / MakeWrite / MakeWrite Folder / MWWindMisc.c < prev   
Encoding:
C/C++ Source or Header  |  1994-02-22  |  4.2 KB  |  223 lines  |  [TEXT/KAHL]

  1. # include    "TransSkel.h"
  2. # include    "TransDisplay.h"
  3.  
  4. # include    "MakeWrite.h"
  5.  
  6.  
  7. static WindowPtr    meterWind = nil;
  8. static WindowPtr    helpWind = nil;
  9. static short        errCount;
  10. static Str255        errWindName;
  11. static short        hPercent;
  12.  
  13. /* ---------------------------------------------------------------- */
  14. /*                    General Display Window Routines                    */
  15. /* ---------------------------------------------------------------- */
  16.  
  17.  
  18. static pascal void
  19. DWindActivate (Boolean active)
  20. {
  21. WindowPtr    w;
  22.  
  23.     if (!active)    /* deactivated - was it closed? */
  24.     {
  25.         GetPort (&w);
  26.         if (((WindowPeek) w)->visible == 0)
  27.         {
  28.             SkelRmveWind (w);    /* yes - remove it */
  29.             if (w == helpWind)
  30.                 helpWind = nil;
  31.         }
  32.     }
  33.     FixMenus ();
  34. }
  35.  
  36.  
  37. /*
  38.  * Build a display window.  NewDWindow makes it the current output
  39.  * window for display output.  The window comes up in front unless
  40.  * the meter is present, in which case it comes up under the meter.
  41.  */
  42.  
  43. void
  44. DisplayWindow (StringPtr title, Boolean visible)
  45. {
  46. static short    i = 0;
  47. WindowPtr    w;
  48. Rect        r;
  49. short        h, v;
  50.  
  51.     if (meterWind != nil && i < 1)
  52.         i = 1;
  53.     h = i * 23 + 5;
  54.     v = h + 65;
  55.     SetRect (&r, h, v, h + 350, v + 200);
  56.     SetDWindowNotify (nil, DWindActivate);
  57.     w = NewDWindow (&r, title, visible, (WindowPtr) -1L, true, 0L);
  58.     if (visible)
  59.         MakeFrontWind (w);
  60.     if (++i == 4)
  61.         i = 0;
  62. }
  63.  
  64.  
  65. /* ---------------------------------------------------------------- */
  66. /*                        Meter Window Routines                        */
  67. /* ---------------------------------------------------------------- */
  68.  
  69.  
  70. void
  71. MeterPos (short h, short lineNo)
  72. {
  73.     SetPort (meterWind);
  74.     MoveTo (h, (short) (lineNo * 16 + 14));
  75. }
  76.  
  77.  
  78. void
  79. MeterString (StringPtr s)
  80. {
  81.     SetPort (meterWind);
  82.     DrawString (s);
  83. }
  84.  
  85.  
  86. void
  87. MeterInt (short i)
  88. {
  89. Str255    s;
  90.  
  91.     NumToString ((short) i, s);
  92.     MeterString (s);
  93. }
  94.  
  95.  
  96. void
  97. StartMeterPercentInfo (void)
  98. {
  99. PenState    p;
  100.  
  101.     MeterString ("\p     ");
  102.     GetPenState (&p);
  103.     hPercent = p.pnLoc.h;
  104. }
  105.  
  106.  
  107. void
  108. SetMeterPercent (short i)
  109. {
  110.     MeterPos (hPercent, 1);
  111.     MeterInt (i);
  112.     MeterString ("\p%");
  113. }
  114.  
  115.  
  116. static pascal void
  117. MeterClobber (void)
  118. {
  119.     DisposeWindow (meterWind);
  120.     meterWind = nil;
  121. }
  122.  
  123.  
  124. void
  125. MeterBegin (void)
  126. {
  127. Rect    r;
  128.  
  129.     SetRect (&r, 0, 0, 340, 36);
  130.     if (SkelQuery (skelQHasColorQD))
  131.     {
  132.         meterWind = NewCWindow (nil, &r, "\p", false, dBoxProc,
  133.                             (WindowPtr) -1L, false, 0L);
  134.     }
  135.     else
  136.     {
  137.         meterWind = NewWindow (nil, &r, "\p", false, dBoxProc,
  138.                             (WindowPtr) -1L, false, 0L);
  139.     }
  140.     SkelWindow (meterWind, nil, nil, nil, nil, nil, MeterClobber, nil, false);
  141.     TextFont (0);
  142.     TextSize (0);
  143.     TextMode (srcCopy);
  144.     SkelPositionWindow (meterWind, skelPositionOnParentDevice,
  145.                                     FixRatio (1, 2), FixRatio (1, 10));
  146.     MakeFrontWind (meterWind);
  147. }
  148.  
  149.  
  150. void
  151. MeterEnd (void)
  152. {
  153.     SkelRmveWind (meterWind);
  154. }
  155.  
  156.  
  157. /* ---------------------------------------------------------------- */
  158. /*                        Error Window Routines                        */
  159. /* ---------------------------------------------------------------- */
  160.  
  161.  
  162. /*
  163.  * Initialize an error window.  This just clears the error count
  164.  * and sets the name that will be given the window if an error
  165.  * occurs.  The window doesn't actually appear unless the error
  166.  * message routine is called.
  167.  */
  168.  
  169. void
  170. ErrWindInit (StringPtr fName)
  171. {
  172.     errCount = 0;
  173.     CopyString (fName, errWindName);
  174. }
  175.  
  176.  
  177. void
  178. ErrWindMsge (StringPtr thing, short value)
  179. {
  180.     if (errCount++ == 0)    /* first error */
  181.     {
  182.         DisplayWindow (errWindName, true);
  183.     }
  184.     DisplayString (thing);
  185.     DisplayShort (value);
  186.     DisplayLn ();
  187. }
  188.  
  189.  
  190. /* ---------------------------------------------------------------- */
  191. /*                        Help Window Routine                            */
  192. /* ---------------------------------------------------------------- */
  193.  
  194.  
  195. /*
  196.  * Create help window, unless it already exists - in which case 
  197.  * simply pull it to the front.
  198.  */
  199.  
  200. void
  201. HelpWindow (void)
  202. {
  203. Rect    r;
  204. Handle    h;
  205.  
  206.     if (helpWind == nil)
  207.     {
  208.         SetRect (&r, 40, 50, 450, 280);
  209.         SetDWindowNotify (nil, DWindActivate);
  210.         helpWind = NewDWindow (&r, "\pInformation Window", false,
  211.                                                 (WindowPtr) -1L, true, 0L);
  212.     
  213.         h = GetResource ('TEXT', helpTextNum);    /* read help text */
  214.         HLock (h);                            /* lock it and write to window */
  215.         DisplayText (*h, GetHandleSize (h));
  216.         HUnlock (h);
  217.         ReleaseResource (h);            /* done with it, so goodbye */
  218.         SetDWindowPos (helpWind, 0);    /* scroll back to top */
  219.         SetDWindow (nil);                /* no more output to this window */
  220.     }
  221.     MakeFrontWind (helpWind);
  222. }
  223.